//上一页
function previousPage(){
	var page = $("#page").val();
	if(page <= 1){
		alert("当前已是首页！");
	}else{
		$("#page").val(page-1);
		loadDatas();
	}
}

//下一页
function nextPage(){
	var page = parseInt($("#page").val());
	var allPage = parseInt($("#allPage").text());
	if(page>=allPage){
		alert("当前已是最后一页！")
	}else{
		$("#page").val(page+1);
		loadDatas();
	}
}

//根据页数跳转
function goPage(){
	var pageIpu = $("#pageIpu").val();
	if(pageIpu == ""){
		alert("请输入跳转的页码！");
	}else{
		pageIpu = parseInt(pageIpu);
		var allPage = parseInt($("#allPage").text());
		if(pageIpu>allPage){
			alert("超出页码范围");
			return false;
		}
		if(pageIpu==0){
			pageIpu += 1;
		}
		$("#pageIpu").val(pageIpu);
		$("#page").val(pageIpu);
		loadDatas();
	}
}

//加载游戏平台下拉数据
function loadGamePlatform(){
	$.ajax({
		type: "post",
		url: "/common/tool/loadgameplatform",
		success: function(msg){
			var datas = msg.records;
			
			var html = "<option value='-1' selected='selected'>全部</option>";
			if(datas.length!=0){
				for(var i = 0; i < datas.length; i++){
					html += "<option value='"+datas[i].packId+"'>"+datas[i].packName+"</option>";
				}
			}
			$("#gamePlatform").html(html);
		}
	});
}

//加载游戏平台下拉数据(图表数据中子页面调用)
function loadGamePlatformForDataCount(){
	$.ajax({
		type: "post",
		url: "../../../php/other/loadGamePlatform.php",
		success: function(msg){
			var datas = msg.records;
			
			var html = "<option value='' selected='selected'>全部</option>";
			if(datas.length!=0){
				for(var i = 0; i < datas.length; i++){
					html += "<option value='"+datas[i].packId+"'>"+datas[i].packName+"</option>";
				}
			}
			$("#gamePlatform").html(html);
		}
	});
}

/*
 * 日期处理开始
 */
var now = new Date();                    //当前日期
var nowDayOfWeek = now.getDay()-1;       //今天本周的第几天
var nowDay = now.getDate();              //当前日
var nowMonth = now.getMonth();           //当前月
var nowYear = now.getYear();             //当前年
nowYear += (nowYear < 2000) ? 1900 : 0;  //

var lastMonthDate = new Date();  //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
var lastYear = lastMonthDate.getYear();
var lastMonth = lastMonthDate.getMonth();

//格式化日期：yyyy-MM-dd
function formatDate(date) {
    var myyear = date.getFullYear();
    var mymonth = date.getMonth()+1;
    var myweekday = date.getDate();

    if(mymonth < 10){
        mymonth = "0" + mymonth;
    }
    if(myweekday < 10){
        myweekday = "0" + myweekday;
    }
    return (myyear+"-"+mymonth + "-" + myweekday);
}

//获得某月的天数
function getMonthDays(myMonth){
    var monthStartDate = new Date(nowYear, myMonth, 1);
    var monthEndDate = new Date(nowYear, myMonth + 1, 1);
    var   days   =   (monthEndDate   -   monthStartDate)/(1000   *   60   *   60   *   24);
    return   days;
}

//获得本季度的开始月份
function getQuarterStartMonth(){
    var quarterStartMonth = 0;
    if(nowMonth<3){
        quarterStartMonth = 0;
    }
    if(2<6){
        quarterStartMonth = 3;
    }
    if(5<9){
        quarterStartMonth = 6;
    }
    if(nowMonth>8){
        quarterStartMonth = 9;
    }
    return quarterStartMonth;
}

//获取多少天前后日期
function GetDateStr(AddDayCount){
	var dd = new Date();
	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
	var y = dd.getFullYear();
	var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);//获取当前月份的日期，不足10补0
	var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();//获取当前几号，不足10补0
	return y+"-"+m+"-"+d;
}

/*
 * 日期处理结束
 */


//处理数字
function doubleFormat(num){
	if(num == ""){
		return "0";
	}else{
		var index = num.indexOf(".");
		if(index != -1){
			if(num.substring(0,index) == ""){
				num = "0"+num;
			}
		}
		return num;
	}
}

//数字转汉字
function numToChinese(obj, num){
	
	var fu = "";
	if(num.indexOf("-") == 0 && num.indexOf("--") != 0 && num.lastIndexOf("-") == 0){
		fu = "负";
		num = num.substring(num.indexOf("-")+1);
	}
	
	//创建实例
	var k = new change(num);
	var numStr = k.pri_ary();
	numStr = numStr.replace("亿万","亿");
	numStr = numStr.replace("一十万","十万");
	if(isNaN(num) || num.indexOf("--") == 0){
		numStr = "这不是数字！";
	}
	if(numStr.indexOf("undefined") != -1){
		fu = "";
		numStr = "数字太大啦！";
	}
	$(obj).html(fu+numStr).attr("title", fu+numStr);
}

//选择某列排序的方式
function changeSortClass(obj){
	var cla = $(obj).attr("class");
	if(cla.indexOf("fa-sort-desc") != -1){
		$(obj).addClass("fa-sort-asc");
		$(obj).removeClass("fa-sort-desc");
	}else{
		$(obj).addClass("fa-sort-desc");
		$(obj).removeClass("fa-sort-asc");
	}
	$(obj).removeClass("fa-sort");
	
	loadDatas('search');
}
//初始化排序
function initSort(obj){
	$(obj).siblings(".sortTh").children().attr("class","fa fa-sort order");
}